**************************************************************************************************
*** This do file creates the replication results for 
*** Katharina Pfaff, Thomas Pluemper and Eric Neumayer.
*** Polarized Politics: Protest Against Covid-19 Containment Policies in the USA 
*** Published in: Political Science Quarterly
							
**************************************************************************************************
**************************************************************************************************
/* Note: You have to change "local DIR" to the directory you copy the original stata files contained 	*/
/* in the zip file and then run the do file. 
/* You must have Stata version 13 or higher installed													*/
**************************************************************************************************
*/

drop _all
clear matrix
clear mata


capture net install outreg2, from(http://fmwww.bc.edu/RePEc/bocode/o) /* checks whether outreg2 is installed 		*/


**********************************************************************************
local DIR = "d:\Research\Health for all database\United States"  /*change relative path to the directory where the files are located */
cd "`DIR'"
***********************************************************************************





** table 1

use "Article for PSQ (C19).dta", clear

tsset


* party & stringency
* republican governor in united government states as reference category
* full sample
nbreg monthly_count_C19_events i.blue_gov_p1_united i.either_gov_p1_divided i.sstate4 i.dummy_state_comp_20 i.governor_Nov2020_elections  containmenthealthindex   new_death_rate ln_pop gdp_pc  pop_density_2019 gini i.month if month>=3, cluster(state_id)
estat ic
mat es_ic = r(S)
local AIC = es_ic[1,5]
local BIC = es_ic[1,6]
outreg2 using table1.xls, excel 2aster replace  addst(Pseudo R-squared, `e(r2_p)', AIC, `AIC', BIC, `BIC')
margins, dydx(*) post
outreg2 using table1.xls, excel 2aster append  
test 1.blue_gov_p1_united= 1.either_gov_p1_divided


* party & stringency
* republican governor in united government states as reference category
* balanced sample
nbreg monthly_count_C19_events i.blue_gov_p1_united  i.sstate4  i.dummy_state_comp_20 i.governor_Nov2020_elections containmenthealthindex  new_death_rate ln_pop gdp_pc  pop_density_2019 gini i.month if month>=3 & balanced==1, cluster(state_id)
estat ic
mat es_ic = r(S)
local AIC = es_ic[1,5]
local BIC = es_ic[1,6]
outreg2 using table1.xls, excel 2aster append  addst(Pseudo R-squared, `e(r2_p)', AIC, `AIC', BIC, `BIC')
margins, dydx(*) post
outreg2 using table1.xls, excel 2aster append  



** table 2

** stringency conditioned by party
use "Article for PSQ (C19).dta", clear

tsset

* full sample
nbreg monthly_count_C19_events blue_gov_p1_united_string  either_gov_p1_div_string red_gov_p1_united_string i.sstate4  i.dummy_state_comp_20 i.governor_Nov2020_elections   new_death_rate ln_pop gdp_pc  pop_density_2019 gini i.month if month>=3 , cluster(state_id)
estat ic
mat es_ic = r(S)
local AIC = es_ic[1,5]
local BIC = es_ic[1,6]
outreg2 using table2.xls, excel 2aster replace  addst(Pseudo R-squared, `e(r2_p)', AIC, `AIC', BIC, `BIC')
margins, dydx(*) post
test blue_gov_p1_united_string = red_gov_p1_united_string
test either_gov_p1_div_string = blue_gov_p1_united_string 
test either_gov_p1_div_string = red_gov_p1_united_string
outreg2 using table2.xls, excel 2aster append  

* balanced sample
nbreg monthly_count_C19_events blue_gov_p1_united_string   red_gov_p1_united_string i.sstate4  i.dummy_state_comp_20 i.governor_Nov2020_elections   new_death_rate ln_pop gdp_pc  pop_density_2019 gini i.month if month>=3 & balanced==1, cluster(state_id)
estat ic
mat es_ic = r(S)
local AIC = es_ic[1,5]
local BIC = es_ic[1,6]
outreg2 using table2.xls, excel 2aster append  addst(Pseudo R-squared, `e(r2_p)', AIC, `AIC', BIC, `BIC')
margins, dydx(*) post
test blue_gov_p1_united_string = red_gov_p1_united_string
outreg2 using table2.xls, excel 2aster append  


** Generate data underlying figure 1 & appendix 1
use "Article for PSQ (C19).dta", clear
keep if red==1
collapse containmenthealthindex monthly_count_C19_events , by(month)
list
use "Article for PSQ (C19).dta", clear
keep if red==1 & balanced==1
collapse containmenthealthindex monthly_count_C19_events , by(month)
list
use "Article for PSQ (C19).dta", clear
keep if blue==1
collapse containmenthealthindex monthly_count_C19_events , by(month)
list
use "Article for PSQ (C19).dta", clear
keep if blue==1 & balanced==1
collapse containmenthealthindex monthly_count_C19_events , by(month)
list


** Appendix 2: Overview of partisanship

use "Article for PSQ (C19).dta", clear

keep statename month blue red either_gov_p1_divided sstate4
keep if month==5
drop month
drop if statename=="District of Columbia"

** Appendix 3a: Summary descriptive stats
* full sample
use "Article for PSQ (C19).dta", clear

quietly nbreg monthly_count_C19_events blue_gov_p1_united either_gov_p1_divided sstate4  dummy_state_comp_20 governor_Nov2020_elections containmenthealthindex   new_death_rate ln_pop gdp_pc  pop_density_2019 gini i.month if month>=3, cluster(state_id)
keep if e(sample)

sum monthly_count_C19_events blue_gov_p1_united either_gov_p1_divided red_gov_p1_united sstate4  dummy_state_comp_20 governor_Nov2020_elections  containmenthealthindex  new_death_rate ln_pop gdp_pc  pop_density_2019 gini

** Appendix 3a: Summary descriptive stats
* balanced sample
use "Article for PSQ (C19).dta", clear

quietly nbreg monthly_count_C19_events blue_gov_p1_united sstate4  dummy_state_comp_20 governor_Nov2020_elections  containmenthealthindex  new_death_rate ln_pop gdp_pc  pop_density_2019 gini i.month if month>=3 & balanced==1, cluster(state_id)
keep if e(sample)

sum monthly_count_C19_events blue_gov_p1_united red_gov_p1_united sstate4  dummy_state_comp_20 governor_Nov2020_elections  containmenthealthindex  new_death_rate ln_pop gdp_pc  pop_density_2019 gini



** Some descriptive statistics (some of which reported in manuscript)

*  protest in total

use "Article for PSQ (C19).dta", clear

quietly nbreg monthly_count_C19_events blue_gov_p1_united either_gov_p1_divided containmenthealthindex  new_death_rate ln_pop gdp_pc  pop_density_2019 gini if month>=3, cluster(state_id)
keep if e(sample)
collapse (sum) monthly_count_C19_events
list 



* total protest across time

use "Article for PSQ (C19).dta", clear

quietly nbreg monthly_count_C19_events blue_gov_p1_united either_gov_p1_divided containmenthealthindex  new_death_rate ln_pop gdp_pc  pop_density_2019 gini if month>=3, cluster(state_id)
keep if e(sample)
gsort -monthly_count_C19_events
list


* total protest across states

use "Article for PSQ (C19).dta", clear

quietly nbreg monthly_count_C19_events blue_gov_p1_united either_gov_p1_divided containmenthealthindex  new_death_rate ln_pop gdp_pc  pop_density_2019 gini if month>=3, cluster(state_id)
keep if e(sample)
collapse (sum) monthly_count_C19_events, by(statename)
gsort -monthly_count_C19_events
list



*  protest in total by partisan state control category

use "Article for PSQ (C19).dta", clear

quietly nbreg monthly_count_C19_events blue_gov_p1_united either_gov_p1_divided containmenthealthindex  new_death_rate ln_pop gdp_pc  pop_density_2019 gini if month>=3, cluster(state_id)
keep if e(sample)
capture drop left_right
gen left_right=0
replace left_right=1 if either_gov_p1_divided==1
replace left_right=2 if red_gov_p1_united==1
collapse (sum) monthly_count_C19_events, by(left_right) 
gsort -monthly_count_C19_events
list



*  stringency by partisan state control category

use "Article for PSQ (C19).dta", clear

quietly nbreg monthly_count_C19_events blue_gov_p1_united either_gov_p1_divided containmenthealthindex  new_death_rate ln_pop gdp_pc  pop_density_2019 gini if month>=3, cluster(state_id)
keep if e(sample)
capture drop left_right
gen left_right=0
replace left_right=1 if either_gov_p1_divided==1
replace left_right=2 if red_gov_p1_united==1
collapse containmenthealthindex, by(left_right) 
gsort -containmenthealthindex
list




* highest and lowest values of stringency in full and balanced sample

* full sample
use "Article for PSQ (C19).dta", clear

quietly nbreg monthly_count_C19_events blue_gov_p1_united either_gov_p1_divided containmenthealthindex  new_death_rate ln_pop gdp_pc  pop_density_2019 gini if month>=3, cluster(state_id)
keep if e(sample)

gsort -containmenthealthindex
list statename month containmenthealthindex


collapse containmenthealthindex, by(statename)
gsort - containmenthealthindex
list 

* balanced sample
use "Article for PSQ (C19).dta", clear

quietly nbreg monthly_count_C19_events blue_gov_p1_united  containmenthealthindex  new_death_rate ln_pop gdp_pc  pop_density_2019 gini if month>=3 & balanced==1 & either_gov_p1_divided==0, cluster(state_id)
keep if e(sample)

gsort -containmenthealthindex
list statename month containmenthealthindex


collapse containmenthealthindex, by(statename)
gsort - containmenthealthindex
list 




* average values of stringency by state control category in full sample

* full sample

use "Article for PSQ (C19).dta", clear

quietly nbreg monthly_count_C19_events blue_gov_p1_united either_gov_p1_divided containmenthealthindex  new_death_rate ln_pop gdp_pc  pop_density_2019 gini if month>=3, cluster(state_id)
keep if e(sample)
capture drop left_right
gen left_right=0
replace left_right=1 if either_gov_p1_divided==1
replace left_right=2 if red_gov_p1_united==1
bys left_right: sum containmenthealthindex, detail






** Generate data underlying figure 2

use "Article for PSQ (C19).dta", clear


quietly sum containmenthealthindex if blue==1 & month==3
replace balanced=1 if month==3 & containmenthealthindex>=`r(min)' & red==1
quietly sum containmenthealthindex if red==1 & month==3
replace balanced=1 if month==3 & containmenthealthindex<=`r(max)' & blue==1
sum containmenthealthindex monthly_count_C19_events if month==3 & red==1 
sum containmenthealthindex monthly_count_C19_events if month==3 & red==1 & balanced==1 
sum containmenthealthindex monthly_count_C19_events if month==3 & blue==1 
sum containmenthealthindex monthly_count_C19_events if month==3 & blue==1 & balanced==1 

quietly sum containmenthealthindex if blue==1 & month==4
replace balanced=1 if month==4 & containmenthealthindex>=`r(min)' & red==1
quietly sum containmenthealthindex if red==1 & month==4
replace balanced=1 if month==4 & containmenthealthindex<=`r(max)' & blue==1
sum containmenthealthindex monthly_count_C19_events if month==4 & red==1 
sum containmenthealthindex monthly_count_C19_events if month==4 & red==1 & balanced==1 
sum containmenthealthindex monthly_count_C19_events if month==4 & blue==1 
sum containmenthealthindex monthly_count_C19_events if month==4 & blue==1 & balanced==1 

quietly sum containmenthealthindex if blue==1 & month==5
replace balanced=1 if month==5 & containmenthealthindex>=`r(min)' & red==1
quietly sum containmenthealthindex if red==1 & month==5
replace balanced=1 if month==5 & containmenthealthindex<=`r(max)' & blue==1
sum containmenthealthindex monthly_count_C19_events if month==5 & red==1 
sum containmenthealthindex monthly_count_C19_events if month==5 & red==1 & balanced==1 
sum containmenthealthindex monthly_count_C19_events if month==5 & blue==1 
sum containmenthealthindex monthly_count_C19_events if month==5 & blue==1 & balanced==1 

quietly sum containmenthealthindex if blue==1 & month==6
replace balanced=1 if month==6 & containmenthealthindex>=`r(min)' & red==1
quietly sum containmenthealthindex if red==1 & month==6
replace balanced=1 if month==6 & containmenthealthindex<=`r(max)' & blue==1
sum containmenthealthindex monthly_count_C19_events if month==6 & red==1 
sum containmenthealthindex monthly_count_C19_events if month==6 & red==1 & balanced==1 
sum containmenthealthindex monthly_count_C19_events if month==6 & blue==1 
sum containmenthealthindex monthly_count_C19_events if month==6 & blue==1 & balanced==1 


quietly sum containmenthealthindex if blue==1 & month==7
replace balanced=1 if month==7 & containmenthealthindex>=`r(min)' & red==1
quietly sum containmenthealthindex if red==1 & month==7
replace balanced=1 if month==7 & containmenthealthindex<=`r(max)' & blue==1
sum containmenthealthindex monthly_count_C19_events if month==7 & red==1 
sum containmenthealthindex monthly_count_C19_events if month==7 & red==1 & balanced==1 
sum containmenthealthindex monthly_count_C19_events if month==7 & blue==1 
sum containmenthealthindex monthly_count_C19_events if month==7 & blue==1 & balanced==1 

quietly sum containmenthealthindex if blue==1 & month==8
replace balanced=1 if month==8 & containmenthealthindex>=`r(min)' & red==1
quietly sum containmenthealthindex if red==1 & month==8
replace balanced=1 if month==8 & containmenthealthindex<=`r(max)' & blue==1
sum containmenthealthindex monthly_count_C19_events if month==8 & red==1 
sum containmenthealthindex monthly_count_C19_events if month==8 & red==1 & balanced==1 
sum containmenthealthindex monthly_count_C19_events if month==8 & blue==1 
sum containmenthealthindex monthly_count_C19_events if month==8 & blue==1 & balanced==1 

quietly sum containmenthealthindex if blue==1 & month==9
replace balanced=1 if month==9 & containmenthealthindex>=`r(min)' & red==1
quietly sum containmenthealthindex if red==1 & month==9
replace balanced=1 if month==9 & containmenthealthindex<=`r(max)' & blue==1
sum containmenthealthindex monthly_count_C19_events if month==9 & red==1 
sum containmenthealthindex monthly_count_C19_events if month==9 & red==1 & balanced==1 
sum containmenthealthindex monthly_count_C19_events if month==9 & blue==1 
sum containmenthealthindex monthly_count_C19_events if month==9 & blue==1 & balanced==1 


quietly sum containmenthealthindex if blue==1 & month==10
replace balanced=1 if month==10 & containmenthealthindex>=`r(min)' & red==1
quietly sum containmenthealthindex if red==1 & month==10
replace balanced=1 if month==10 & containmenthealthindex<=`r(max)' & blue==1
sum containmenthealthindex monthly_count_C19_events if month==10 & red==1 
sum containmenthealthindex monthly_count_C19_events if month==10 & red==1 & balanced==1 
sum containmenthealthindex monthly_count_C19_events if month==10 & blue==1 
sum containmenthealthindex monthly_count_C19_events if month==10 & blue==1 & balanced==1 

quietly sum containmenthealthindex if blue==1 & month==11
replace balanced=1 if month==11 & containmenthealthindex>=`r(min)' & red==1
quietly sum containmenthealthindex if red==1 & month==11
replace balanced=1 if month==11 & containmenthealthindex<=`r(max)' & blue==1
sum containmenthealthindex monthly_count_C19_events if month==11 & red==1 
sum containmenthealthindex monthly_count_C19_events if month==11 & red==1 & balanced==1 
sum containmenthealthindex monthly_count_C19_events if month==11 & blue==1 
sum containmenthealthindex monthly_count_C19_events if month==11 & blue==1 & balanced==1 

quietly sum containmenthealthindex if blue==1 & month==12
replace balanced=1 if month==12 & containmenthealthindex>=`r(min)' & red==1
quietly sum containmenthealthindex if red==1 & month==12
replace balanced=1 if month==12 & containmenthealthindex<=`r(max)' & blue==1
sum containmenthealthindex monthly_count_C19_events if month==12 & red==1 
sum containmenthealthindex monthly_count_C19_events if month==12 & red==1 & balanced==1 
sum containmenthealthindex monthly_count_C19_events if month==12 & blue==1 
sum containmenthealthindex monthly_count_C19_events if month==12 & blue==1 & balanced==1 

quietly sum containmenthealthindex if blue==1 & month==13
replace balanced=1 if month==13 & containmenthealthindex>=`r(min)' & red==1
quietly sum containmenthealthindex if red==1 & month==13
replace balanced=1 if month==13 & containmenthealthindex<=`r(max)' & blue==1
sum containmenthealthindex monthly_count_C19_events if month==13 & red==1 
sum containmenthealthindex monthly_count_C19_events if month==13 & red==1 & balanced==1 
sum containmenthealthindex monthly_count_C19_events if month==13 & blue==1 
sum containmenthealthindex monthly_count_C19_events if month==13 & blue==1 & balanced==1 

quietly sum containmenthealthindex if blue==1 & month==14
replace balanced=1 if month==14 & containmenthealthindex>=`r(min)' & red==1
quietly sum containmenthealthindex if red==1 & month==14
replace balanced=1 if month==14 & containmenthealthindex<=`r(max)' & blue==1
sum containmenthealthindex monthly_count_C19_events if month==14 & red==1 
sum containmenthealthindex monthly_count_C19_events if month==14 & red==1 & balanced==1 
sum containmenthealthindex monthly_count_C19_events if month==14 & blue==1 
sum containmenthealthindex monthly_count_C19_events if month==14 & blue==1 & balanced==1 


quietly sum containmenthealthindex if blue==1 & month==15
replace balanced=1 if month==15 & containmenthealthindex>=`r(min)' & red==1
quietly sum containmenthealthindex if red==1 & month==15
replace balanced=1 if month==15 & containmenthealthindex<=`r(max)' & blue==1
sum containmenthealthindex monthly_count_C19_events if month==15 & red==1 
sum containmenthealthindex monthly_count_C19_events if month==15 & red==1 & balanced==1 
sum containmenthealthindex monthly_count_C19_events if month==15 & blue==1 
sum containmenthealthindex monthly_count_C19_events if month==15 & blue==1 & balanced==1 


quietly sum containmenthealthindex if blue==1 & month==16
replace balanced=1 if month==16 & containmenthealthindex>=`r(min)' & red==1
quietly sum containmenthealthindex if red==1 & month==16
replace balanced=1 if month==16 & containmenthealthindex<=`r(max)' & blue==1
sum containmenthealthindex monthly_count_C19_events if month==16 & red==1 
sum containmenthealthindex monthly_count_C19_events if month==16 & red==1 & balanced==1 
sum containmenthealthindex monthly_count_C19_events if month==16 & blue==1 
sum containmenthealthindex monthly_count_C19_events if month==16 & blue==1 & balanced==1 



sum containmenthealthindex if blue==1 & month==17
replace balanced=1 if month==17 & containmenthealthindex>=`r(min)' & red==1
sum containmenthealthindex if red==1 & month==17
replace balanced=1 if month==17 & containmenthealthindex<=`r(max)' & blue==1
sum containmenthealthindex monthly_count_C19_events if month==17 & red==1 
sum containmenthealthindex monthly_count_C19_events if month==17 & red==1 & balanced==1 
sum containmenthealthindex monthly_count_C19_events if month==17 & blue==1 
sum containmenthealthindex monthly_count_C19_events if month==17 & blue==1 & balanced==1 


sum containmenthealthindex if blue==1 & month==18
replace balanced=1 if month==18 & containmenthealthindex>=`r(min)' & red==1
sum containmenthealthindex if red==1 & month==18
replace balanced=1 if month==18 & containmenthealthindex<=`r(max)' & blue==1
sum containmenthealthindex monthly_count_C19_events if month==18 & red==1 
sum containmenthealthindex monthly_count_C19_events if month==18 & red==1 & balanced==1 
sum containmenthealthindex monthly_count_C19_events if month==18 & blue==1 
sum containmenthealthindex monthly_count_C19_events if month==18 & blue==1 & balanced==1 


sum containmenthealthindex if blue==1 & month==19
replace balanced=1 if month==19 & containmenthealthindex>=`r(min)' & red==1
sum containmenthealthindex if red==1 & month==19
replace balanced=1 if month==19 & containmenthealthindex<=`r(max)' & blue==1
sum containmenthealthindex monthly_count_C19_events if month==19 & red==1 
sum containmenthealthindex monthly_count_C19_events if month==19 & red==1 & balanced==1 
sum containmenthealthindex monthly_count_C19_events if month==19 & blue==1 
sum containmenthealthindex monthly_count_C19_events if month==19 & blue==1 & balanced==1 


sum containmenthealthindex if blue==1 & month==20
replace balanced=1 if month==20 & containmenthealthindex>=`r(min)' & red==1
sum containmenthealthindex if red==1 & month==20
replace balanced=1 if month==20 & containmenthealthindex<=`r(max)' & blue==1
sum containmenthealthindex monthly_count_C19_events if month==20 & red==1 
sum containmenthealthindex monthly_count_C19_events if month==20 & red==1 & balanced==1 
sum containmenthealthindex monthly_count_C19_events if month==20 & blue==1 
sum containmenthealthindex monthly_count_C19_events if month==20 & blue==1 & balanced==1 


sum containmenthealthindex if blue==1 & month==21
replace balanced=1 if month==21 & containmenthealthindex>=`r(min)' & red==1
sum containmenthealthindex if red==1 & month==21
replace balanced=1 if month==21 & containmenthealthindex<=`r(max)' & blue==1
sum containmenthealthindex monthly_count_C19_events if month==21 & red==1 
sum containmenthealthindex monthly_count_C19_events if month==21 & red==1 & balanced==1 
sum containmenthealthindex monthly_count_C19_events if month==21 & blue==1 
sum containmenthealthindex monthly_count_C19_events if month==21 & blue==1 & balanced==1 


sum containmenthealthindex if blue==1 & month==22
replace balanced=1 if month==22 & containmenthealthindex>=`r(min)' & red==1
sum containmenthealthindex if red==1 & month==22
replace balanced=1 if month==22 & containmenthealthindex<=`r(max)' & blue==1
sum containmenthealthindex monthly_count_C19_events if month==22 & red==1 
sum containmenthealthindex monthly_count_C19_events if month==22 & red==1 & balanced==1 
sum containmenthealthindex monthly_count_C19_events if month==22 & blue==1 
sum containmenthealthindex monthly_count_C19_events if month==22 & blue==1 & balanced==1 


sum containmenthealthindex if blue==1 & month==23
replace balanced=1 if month==23 & containmenthealthindex>=`r(min)' & red==1
sum containmenthealthindex if red==1 & month==23
replace balanced=1 if month==23 & containmenthealthindex<=`r(max)' & blue==1
sum containmenthealthindex monthly_count_C19_events if month==23 & red==1 
sum containmenthealthindex monthly_count_C19_events if month==23 & red==1 & balanced==1 
sum containmenthealthindex monthly_count_C19_events if month==23 & blue==1 
sum containmenthealthindex monthly_count_C19_events if month==23 & blue==1 & balanced==1 


sum containmenthealthindex if blue==1 & month==24
replace balanced=1 if month==24 & containmenthealthindex>=`r(min)' & red==1
sum containmenthealthindex if red==1 & month==24
replace balanced=1 if month==24 & containmenthealthindex<=`r(max)' & blue==1
sum containmenthealthindex monthly_count_C19_events if month==24 & red==1 
sum containmenthealthindex monthly_count_C19_events if month==24 & red==1 & balanced==1 
sum containmenthealthindex monthly_count_C19_events if month==24 & blue==1 
sum containmenthealthindex monthly_count_C19_events if month==24 & blue==1 & balanced==1 


sum containmenthealthindex if blue==1 & month==25
replace balanced=1 if month==25 & containmenthealthindex>=`r(min)' & red==1
sum containmenthealthindex if red==1 & month==25
replace balanced=1 if month==25 & containmenthealthindex<=`r(max)' & blue==1
sum containmenthealthindex monthly_count_C19_events if month==25 & red==1 
sum containmenthealthindex monthly_count_C19_events if month==25 & red==1 & balanced==1 
sum containmenthealthindex monthly_count_C19_events if month==25 & blue==1 
sum containmenthealthindex monthly_count_C19_events if month==25 & blue==1 & balanced==1 


sum containmenthealthindex if blue==1 & month==26
replace balanced=1 if month==26 & containmenthealthindex>=`r(min)' & red==1
sum containmenthealthindex if red==1 & month==26
replace balanced=1 if month==26 & containmenthealthindex<=`r(max)' & blue==1
sum containmenthealthindex monthly_count_C19_events if month==26 & red==1 
sum containmenthealthindex monthly_count_C19_events if month==26 & red==1 & balanced==1 
sum containmenthealthindex monthly_count_C19_events if month==26 & blue==1 
sum containmenthealthindex monthly_count_C19_events if month==26 & blue==1 & balanced==1 


sum containmenthealthindex if blue==1 & month==27
replace balanced=1 if month==27 & containmenthealthindex>=`r(min)' & red==1
sum containmenthealthindex if red==1 & month==27
replace balanced=1 if month==27 & containmenthealthindex<=`r(max)' & blue==1
sum containmenthealthindex monthly_count_C19_events if month==27 & red==1 
sum containmenthealthindex monthly_count_C19_events if month==27 & red==1 & balanced==1 
sum containmenthealthindex monthly_count_C19_events if month==27 & blue==1 
sum containmenthealthindex monthly_count_C19_events if month==27 & blue==1 & balanced==1 


** Generate data underlying figure 1 - alternative way

* Alternative Way of Producing Table 1
* All red
use "Article for PSQ (C19).dta", clear
keep if red==1
collapse containmenthealthindex monthly_count_C19_events , by(month)
list

* Red balanced
use "Article for PSQ (C19).dta", clear
keep if red==1 & balanced==1
collapse containmenthealthindex monthly_count_C19_events , by(month)
list

* All blue
use "Article for PSQ (C19).dta", clear
keep if blue==1
collapse containmenthealthindex monthly_count_C19_events , by(month)
list

* Blue balanced
use "Article for PSQ (C19).dta", clear
keep if blue==1 & balanced==1
collapse containmenthealthindex monthly_count_C19_events , by(month)
list





** Generate data underlying figure 2

*** Full sample

use "Article for PSQ (C19).dta", clear

* party & stringency
* republican governor in united government states as reference category
nbreg monthly_count_C19_events i.blue_gov_p1_united i.either_gov_p1_divided i.sstate4 i.dummy_state_comp_20 i.governor_Nov2020_elections  containmenthealthindex   new_death_rate ln_pop gdp_pc  pop_density_2019 gini i.month if month>=3, cluster(state_id)
keep if e(sample)
capture drop  counter_min_atasobs
gen  counter_min_atasobs=.

capture drop holder 
predict holder

capture drop x1_holder 
gen x1_holder=blue_gov_p1_united

quietly sum blue_gov_p1_united
replace blue_gov_p1_united = `r(min)'


capture drop holder2
predict holder2
replace blue_gov_p1_united=x1_holder


qui replace counter_min_atasobs = (holder-holder2)

ren counter_min_atasobs partisan_counter_min

nbreg monthly_count_C19_events i.red_gov_p1_united i.either_gov_p1_divided i.sstate4 i.dummy_state_comp_20 i.governor_Nov2020_elections  containmenthealthindex   new_death_rate ln_pop gdp_pc  pop_density_2019 gini i.month if month>=3, cluster(state_id)
keep if e(sample)

capture drop holder 
predict holder

capture drop x1_holder 
gen x1_holder=red_gov_p1_united

quietly sum red_gov_p1_united
replace red_gov_p1_united = `r(min)'


capture drop holder2 
predict holder2
replace red_gov_p1_united=x1_holder


qui replace partisan_counter_min = (holder-holder2)*-1 if red_gov_p1_united==1


keep statename month monthly_count_C19_events blue_gov_p1_united either_gov_p1_divided  partisan_counter_min 

replace partisan_counter_min=. if either_gov_p1_divided==1

save "counterfactual at sample minima effects partisan", replace


use "Article for PSQ (C19).dta", clear


* party & stringency
* republican governor in united government states as reference category
nbreg monthly_count_C19_events i.blue_gov_p1_united i.either_gov_p1_divided i.sstate4 i.dummy_state_comp_20 i.governor_Nov2020_elections  containmenthealthindex   new_death_rate ln_pop gdp_pc  pop_density_2019 gini i.month if month>=3, cluster(state_id)
keep if e(sample)
capture drop  counter_min_atasobs
gen  counter_min_atasobs=.

capture drop holder 
predict holder

capture drop x3_holder 
gen x3_holder=containmenthealthindex

quietly sum containmenthealthindex
replace containmenthealthindex = `r(min)'


capture drop holder2
predict holder2

replace containmenthealthindex=x3_holder

qui replace counter_min_atasobs = (holder-holder2)

ren counter_min_atasobs stringency_counter_min

keep statename month monthly_count_C19_events blue_gov_p1_united red_gov_p1_united either_gov_p1_divided containmenthealthindex  stringency_counter_min 

replace stringency_counter_min=. if either_gov_p1_divided==1

save "counterfactual at sample minima effects stringency", replace


mmerge statename month using "counterfactual at sample minima effects partisan"

drop _merge

order  statename month monthly_count_C19_events blue_gov_p1_united red_gov_p1_united either_gov_p1_divided containmenthealthindex  partisan_counter_min stringency_counter_min 


ren partisan_counter_min partisan_counter_min_full
ren stringency_counter_min stringency_counter_min_full



save "table 2 - full sample count effects", replace






*** Balanced sample



use "Article for PSQ (C19).dta", clear


* party & stringency
* republican governor in united government states as reference category
nbreg monthly_count_C19_events i.blue_gov_p1_united  i.sstate4  i.dummy_state_comp_20 i.governor_Nov2020_elections containmenthealthindex  new_death_rate ln_pop gdp_pc  pop_density_2019 gini i.month if month>=3 & balanced==1, cluster(state_id)
keep if e(sample)
capture drop  counter_min_atasobs
gen  counter_min_atasobs=.

capture drop holder
predict holder

capture drop x1_holder
gen x1_holder=blue_gov_p1_united

quietly sum blue_gov_p1_united
replace blue_gov_p1_united = `r(min)'


capture drop holder2
predict holder2
replace blue_gov_p1_united=x1_holder


qui replace counter_min_atasobs = (holder-holder2)

ren counter_min_atasobs partisan_counter_min

nbreg monthly_count_C19_events i.red_gov_p1_united  i.sstate4  i.dummy_state_comp_20 i.governor_Nov2020_elections containmenthealthindex  new_death_rate ln_pop gdp_pc  pop_density_2019 gini i.month if month>=3 & balanced==1, cluster(state_id)
keep if e(sample)

capture drop holder
predict holder

capture drop x1_holder
gen x1_holder=red_gov_p1_united

quietly sum red_gov_p1_united
replace red_gov_p1_united = `r(min)'


capture drop holder2
predict holder2
replace red_gov_p1_united=x1_holder


qui replace partisan_counter_min = (holder-holder2)*-1 if red_gov_p1_united==1


keep statename month monthly_count_C19_events blue_gov_p1_united  containmenthealthindex  partisan_counter_min 


save "counterfactual at sample minima effects partisan", replace






use "Article for PSQ (C19).dta", clear


* party & stringency
* republican governor in united government states as reference category
nbreg monthly_count_C19_events i.blue_gov_p1_united  i.sstate4  i.dummy_state_comp_20 i.governor_Nov2020_elections containmenthealthindex  new_death_rate ln_pop gdp_pc  pop_density_2019 gini i.month if month>=3 & balanced==1, cluster(state_id)
keep if e(sample)
capture drop  counter_min_atasobs
gen  counter_min_atasobs=.

capture drop holder
predict holder


capture drop x3_holder
gen x3_holder=containmenthealthindex

quietly sum containmenthealthindex
replace containmenthealthindex = `r(min)'


capture drop holder2
predict holder2

replace containmenthealthindex=x3_holder

qui replace counter_min_atasobs = (holder-holder2)

ren counter_min_atasobs stringency_counter_min

keep statename month monthly_count_C19_events blue_gov_p1_united  containmenthealthindex  stringency_counter_min 

save "counterfactual at sample minima effects stringency", replace


mmerge statename month using "counterfactual at sample minima effects partisan"

drop _merge

order  statename month monthly_count_C19_events blue_gov_p1_united  containmenthealthindex  partisan_counter_min stringency_counter_min 


ren partisan_counter_min partisan_counter_min_balanced
ren stringency_counter_min stringency_counter_min_balanced

save "table 2 - balanced sample count effects", replace




*** Merge counterfactual results from full and balanced sample

use "table 2 - full sample count effects", clear

mmerge statename month using "table 2 - balanced sample count effects"


keep  statename month monthly_count_C19_events blue_gov_p1_united red_gov_p1_united either_gov_p1_divided  containmenthealthindex  partisan_counter_min_full stringency_counter_min_full  partisan_counter_min_balanced stringency_counter_min_balanced 


save "table 2 - full and balanced count effects", replace


save "data for Thomas figure 1.dta", replace




** Generate data underlying figure 3


*** Full sample

use "Article for PSQ (C19).dta", clear


* party & stringency
* republican governor in united government states as reference category
nbreg monthly_count_C19_events blue_gov_p1_united_string  either_gov_p1_div_string red_gov_p1_united_string i.sstate4  i.dummy_state_comp_20 i.governor_Nov2020_elections   new_death_rate ln_pop gdp_pc  pop_density_2019 gini i.month if month>=3 , cluster(state_id)
keep if e(sample)
capture drop  counter_min_atasobs
gen  counter_min_atasobs=.

capture drop holder
predict holder

capture drop x1_holder
gen x1_holder=blue_gov_p1_united_string

quietly sum containmenthealthindex
replace blue_gov_p1_united_string = `r(min)'


capture drop holder2
predict holder2
replace blue_gov_p1_united_string=x1_holder


qui replace counter_min_atasobs = (holder-holder2) if blue_gov_p1_united==1


ren counter_min_atasobs stringency_blue_counter_min

nbreg monthly_count_C19_events blue_gov_p1_united_string  either_gov_p1_div_string red_gov_p1_united_string i.sstate4  i.dummy_state_comp_20 i.governor_Nov2020_elections   new_death_rate ln_pop gdp_pc  pop_density_2019 gini i.month if month>=3 , cluster(state_id)
keep if e(sample)
capture drop  counter_min_atasobs
gen  counter_min_atasobs=.

capture drop holder
predict holder

capture drop x1_holder
gen x1_holder=red_gov_p1_united_string

quietly sum containmenthealthindex
replace red_gov_p1_united_string = `r(min)'


capture drop holder2
predict holder2
replace red_gov_p1_united_string=x1_holder


qui replace counter_min_atasobs = (holder-holder2) if red_gov_p1_united==1


ren counter_min_atasobs stringency_red_counter_min



nbreg monthly_count_C19_events blue_gov_p1_united_string  either_gov_p1_div_string red_gov_p1_united_string i.sstate4  i.dummy_state_comp_20 i.governor_Nov2020_elections   new_death_rate ln_pop gdp_pc  pop_density_2019 gini i.month if month>=3 , cluster(state_id)
keep if e(sample)
capture drop  counter_min_atasobs
gen  counter_min_atasobs=.

capture drop holder
predict holder

capture drop x1_holder
gen x1_holder=either_gov_p1_div_string

quietly sum containmenthealthindex
replace either_gov_p1_div_string = `r(min)'


capture drop holder2
predict holder2
replace either_gov_p1_div_string=x1_holder


qui replace counter_min_atasobs = (holder-holder2) if either_gov_p1_divided==1==1
ren counter_min_atasobs stringency_either_counter_min

*
keep statename month monthly_count_C19_events blue_gov_p1_united red_gov_p1_united either_gov_p1_divided containmenthealthindex blue_gov_p1_united_string  either_gov_p1_div_string red_gov_p1_united_string stringency_blue_counter_min stringency_red_counter_min stringency_either_counter_min


order  statename month monthly_count_C19_events blue_gov_p1_united red_gov_p1_united either_gov_p1_divided containmenthealthindex blue_gov_p1_united_string  either_gov_p1_div_string red_gov_p1_united_string stringency_blue_counter_min stringency_red_counter_min stringency_either_counter_min


save "table 3 - full sample count effects", replace





*** Balanced sample

use "Article for PSQ (C19).dta", clear

* party & stringency
* republican governor in united government states as reference category
nbreg monthly_count_C19_events blue_gov_p1_united_string   red_gov_p1_united_string i.sstate4  i.dummy_state_comp_20 i.governor_Nov2020_elections   new_death_rate ln_pop gdp_pc  pop_density_2019 gini i.month if month>=3 & balanced==1, cluster(state_id)
keep if e(sample)
capture drop  counter_min_atasobs
gen  counter_min_atasobs=.

capture drop holder
predict holder

capture drop x1_holder
gen x1_holder=blue_gov_p1_united_string

quietly sum containmenthealthindex
replace blue_gov_p1_united_string = `r(min)'


capture drop holder2
predict holder2
replace blue_gov_p1_united_string=x1_holder


qui replace counter_min_atasobs = (holder-holder2)  if blue_gov_p1_united==1

ren counter_min_atasobs stringency_blue_counter_min

nbreg monthly_count_C19_events blue_gov_p1_united_string   red_gov_p1_united_string i.sstate4  i.dummy_state_comp_20 i.governor_Nov2020_elections   new_death_rate ln_pop gdp_pc  pop_density_2019 gini i.month if month>=3 & balanced==1, cluster(state_id)
keep if e(sample)
capture drop  counter_min_atasobs
gen  counter_min_atasobs=.

capture drop holder
predict holder

capture drop x1_holder
gen x1_holder=red_gov_p1_united_string

quietly sum containmenthealthindex
replace red_gov_p1_united_string = `r(min)'

capture drop holder2
predict holder2
replace red_gov_p1_united_string=x1_holder


qui replace counter_min_atasobs = (holder-holder2)   if red_gov_p1_united==1
ren counter_min_atasobs stringency_red_counter_min




keep statename month monthly_count_C19_events blue_gov_p1_united  containmenthealthindex blue_gov_p1_united_string  either_gov_p1_div_string red_gov_p1_united_string stringency_blue_counter_min stringency_red_counter_min balanced


order  statename month monthly_count_C19_events blue_gov_p1_united  containmenthealthindex blue_gov_p1_united_string   red_gov_p1_united_string stringency_blue_counter_min stringency_red_counter_min balanced


save "table 3 - balanced sample count effects", replace

use  "table 3 - full sample count effects", clear


ren stringency_blue_counter_min  stringency_blue_counter_full
ren stringency_red_counter_min  stringency_red_counter_full
ren stringency_either_counter_min stringency_either_counter_full

mmerge statename month using "table 3 - balanced sample count effects"

ren stringency_blue_counter_min  stringency_blue_counter_balanced
ren stringency_red_counter_min  stringency_red_counter_balanced


replace balanced=0 if balanced==.

save "table 3 - full and balanced count effects", replace


